/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package system;

import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Dhruv
 */

//class renders images for the nodes of the tree
public class MyRenderer extends DefaultTreeCellRenderer {
    //icons used to decorate the nodes
    Icon inboxIcon, outboxIcon, junkIcon, draftIcon,
            deletedIcon, uniIcon, workIcon;

    //constructor
    public MyRenderer(Icon inboxIcon, Icon outboxIcon, Icon junkIcon,
            Icon draftIcon, Icon deletedIcon, Icon uniIcon, Icon workIcon) {
        this.inboxIcon = inboxIcon;
        this.outboxIcon = outboxIcon;
        this.junkIcon = junkIcon;
        this.draftIcon = draftIcon;
        this.deletedIcon = deletedIcon;
        this.uniIcon = uniIcon;
        this.workIcon = workIcon;
    }

    //method returns the Component that the renderer uses to draw the value
    public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean sel, boolean expanded, boolean leaf,
            int row, boolean hasFocus) {

        super.getTreeCellRendererComponent(tree, value, sel, expanded,
                leaf, row, hasFocus);

        //if node is a leaf
        if (leaf) {
            //set the icons for the respective leaves
            switch (row) {
                case 2: setIcon(inboxIcon); break;
                case 3: setIcon(outboxIcon); break;
                case 4: setIcon(junkIcon); break;
                case 5: setIcon(draftIcon); break;
                case 6: setIcon(deletedIcon); break;
                case 8: setIcon(uniIcon); break;
                case 9: setIcon(workIcon); break;
                default: setIcon(new ImageIcon("folder.png")); break;
            }
        } else {
            //the parent nodes use the following icon
            setIcon(new ImageIcon("folder.png"));
        }

        return this;
    }
}
